﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

using SharedGenomics.Core;

namespace SharedGenomics.Domain
{
    [DataContract]
    public class ScaleFileSchemaColumn : FileSchemaColumn
    {
        public ScaleFileSchemaColumn()
            : base(ColumnDistribution.Scale)
        {
        }

        public override void Validate(string value, ValidationMessageCollection validationMessages)
        {
            Scale s;

            if (!(value.IsEmptyOrWhitespace() || Scale.TryParse(value, out s)))
            {
                validationMessages.AddWarningMessage(String.Format("Unable to convert '{0}' into a Scale value", value));
            }
        }

        public override object Parse(string value)
        {
            Scale s;
            return Scale.TryParse(value, out s)
                ? (object)s
                : null;
        }

        public void AddMissingValue(string missingValue)
        {
            this.AddValue(missingValue, null, true);
        }

        public IEnumerable<string> MissingValues
        {
            get { return this.MissingValuesCore; }
        }

        public override bool IsValidPhenotypeColumn
        {
            get { return true; }
        }

        [OnDeserializing]
        internal void OnDeserialising(StreamingContext context)
        {
            this.Initialize();
        }
    }
}
